/*
 *  CEMenuItemSpriteText.cpp
 *  LID Library
 *
 *  Created by Alexander Trutchenko on 09/11/11.
 *  Copyright 2011 League of Independent Developers. All rights reserved.
 *
 */

#include "cocos2dx_extentions/controls/CEMenuItemSpriteText.h"


using namespace cocos2d;

namespace cocosext {

/////////////////////////////////////////////////////
//
/** CEMenuItemSpriteText 
* 
*/
/////////////////////////////////////////////////////

CEMenuItemSpriteText * CEMenuItemSpriteText::itemFromNormalSprite(const CETextDescription& textInfo, CCNode *normalSprite, CCNode *selectedSprite, CCNode *disabledSprite, CCObject *target, SEL_MenuHandler selector)
{
    CEMenuItemSpriteText *pRet = new CEMenuItemSpriteText();
    pRet->initFromNormalSprite(textInfo, normalSprite, selectedSprite, disabledSprite, target, selector); 
    pRet->autorelease();
    return pRet;
}

/////////////////////////////////////////////////////
//
  
bool CEMenuItemSpriteText::initFromNormalSprite(const CETextDescription& textInfo, CCNode* normalSprite, CCNode* selectedSprite, CCNode* disabledSprite, CCObject* target, SEL_MenuHandler selector)
{
	if (!CEMenuItemSprite::initFromNormalSprite(normalSprite, selectedSprite, disabledSprite, target, selector))
		return false;
	
	
	_pNormalText = CELabelMBFontWrapperScissored::node(textInfo.pNormalText, textInfo.textAllign);
	_pNormalText->setAnchorPoint(CCPointZero);
	_pNormalText->setPosition(ccp(textInfo.marginLeft, textInfo.marginBottom));
	_pNormalText->setContentSize(CCSize(normalSprite->getContentSize().width - textInfo.marginLeft - textInfo.marginRight,
										normalSprite->getContentSize().height - textInfo.marginTop - textInfo.marginBottom));
	normalSprite->addChild(_pNormalText);

    _pSelectedText = CELabelMBFontWrapperScissored::node(textInfo.pSelectedText, textInfo.textAllign);
	_pSelectedText->setAnchorPoint(CCPointZero);
	_pSelectedText->setPosition(ccp(textInfo.marginLeft, textInfo.marginBottom));
	_pSelectedText->setContentSize(CCSize(selectedSprite->getContentSize().width - textInfo.marginLeft - textInfo.marginRight,
										  selectedSprite->getContentSize().height - textInfo.marginTop - textInfo.marginBottom));
	selectedSprite->addChild(_pSelectedText);    

	if (disabledSprite != NULL)
	{
		_pDisabledText = CELabelMBFontWrapperScissored::node(textInfo.pDisabledText, textInfo.textAllign);
		_pDisabledText->setAnchorPoint(CCPointZero);
		_pDisabledText->setPosition(ccp(textInfo.marginLeft, textInfo.marginBottom));
		_pDisabledText->setContentSize(CCSize(disabledSprite->getContentSize().width - textInfo.marginLeft - textInfo.marginRight,
											  disabledSprite->getContentSize().height - textInfo.marginTop - textInfo.marginBottom));
		disabledSprite->addChild(_pDisabledText);
	}

	return true;
}

/////////////////////////////////////////////////////
// CELabelProtocol interface
void CEMenuItemSpriteText::setString(const wchar_t *str)
{
	_pNormalText->setString(str);
    _pSelectedText->setString(str);
	if (_pDisabledText != NULL)
		_pDisabledText->setString(str);
}


/////////////////////////////////////////////////////
// Cocos2d interface
void CEMenuItemSpriteText::setRotation(float fRotation)
{
	CCAssert(false, "CEMenuItemSpriteText::setRotation: CENodeScissored node can't be rotated!");
}

}; // end namespace cocosext

